package com.itheima.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.constant.MessageConstant;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.entity.Result;
import com.itheima.pojo.Movement;
import com.itheima.service.MovementService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping(path="/movement")
public class MovementController {

    @Reference
    private MovementService movementService;

    //分页查询
    @PostMapping(path = "selectMovementByCondition")
    public Result findPage(@RequestBody QueryPageBean queryPageBean){
        try {
            PageResult pageResult=movementService.pageQuery(queryPageBean);
                return new Result(true, MessageConstant.QUERY_MOVEMENT_SUCCESS,pageResult);
            }catch (Exception e){
            e.printStackTrace();
            return new Result(false,MessageConstant.QUERY_MOVEMENT_FAIL);
        }
    }
    @GetMapping("/findAll")
    public Result findAll(){
        List<Movement> movementList=movementService.findAll();
        return new Result(true,MessageConstant.QUERY_MOVEMENT_SUCCESS,movementList);
    }

}
